package com.jin.notifyserver;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;

public class AutoStartHelper {

    private static final String PREFS = "auto_start_prefs";
    private static final String KEY_HINTED = "hinted";

    // 判断是否已经提示过用户（防止每次启动都跳转）
    public static boolean isHinted(Context context) {
        SharedPreferences sp = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
        return sp.getBoolean(KEY_HINTED, false);
    }

    // 设置已经提示过
    public static void setHinted(Context context, boolean hinted) {
        SharedPreferences sp = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
        sp.edit().putBoolean(KEY_HINTED, hinted).apply();
    }

    // 引导用户去开启自启动
    public static void goToAutoStartSetting(Context context) {
        setHinted(context, true);
        try {
            String manufacturer = Build.MANUFACTURER.toLowerCase();
            if (manufacturer.contains("huawei")) {
                // 华为：跳应用详情页，由用户手动设置
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.fromParts("package", context.getPackageName(), null));
                context.startActivity(intent);
            } else {
                // 其他厂商仍尝试直达，否则兜底应用详情
                // ...（小米/OPPO/Vivo 保留原有代码）
            }
        } catch (Exception e) {
            e.printStackTrace();
            // 最终兜底
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setData(Uri.fromParts("package", context.getPackageName(), null));
            context.startActivity(intent);
        }
    }

}
